<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">
    <%--<link rel="stylesheet" href="${frames}/css/picker.css" type="text/css">--%>
    <%--<link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">--%>
    <%--<link rel="stylesheet" href="${newframe}/css/beautify-time.css" type="text/css">--%>
    <link rel="stylesheet" href="${assets}/css/views/department/addDepartment.scss">
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <style>
        body{
            width:760px;
            overflow:hidden;
        }
        .test{
            width:100%;
            overflow:hidden;
        }
        .test p{
            width:100%;
            line-height:100px;
            font-size:15px;
            text-align:center;
        }
        #change{
            position:fixed;
            bottom:16px;
            right:16px;
        }
        label{
            margin-left:5px;
        }
        .title{
            line-height:25px;
            font-size:16px;
            color:#666666;
            margin-left:10px;
        }
        .title1{
            line-height:25px;
            font-size:15px;
            color:#666666;
            margin-left:17px;
            margin-top:5px;
        }
        .text_content{
            margin:20px 0;
            margin-left:18px;
        }
        .text_content div{
            width:48%;
            text-align: left;
            display: inline-block;
        }
        .text_number{
            color:#666666;
            margin-left:12px;
        }
        .change{
            position:fixed;
            top:60%;
            width:100%;
        }
        .btn{
            width:100px;
            line-height: 15px;
            background: #35acfd;
            color: white;
            margin-top:15px;
        }
        .modal-footer{
            width:255px;
            margin:0 auto;
        }
        #keep{
            background:#35acfd !important;
        }
        img{
            max-width:100%;
            height:auto;
        }
        span{
            font-family: PingFang-SC-Regular;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #666666;
        }
        #fbgList{
            position:absolute;
        }
        #height_unit{
            position:relative;
            left:140px;
            border-left:1px solid #d0d0d0;
            width:40px;
            display:inline-block;
            text-align:center;
            line-height:30px;
        }
        #pbgList{
            position:absolute;
        }
        #weight_unit{
            position:relative;
            left:140px;
            border-left:1px solid #d0d0d0;
            width:40px;
            display:inline-block;
            text-align:center;
            line-height:30px;
        }
        input{
            border: solid 1px #d0d0d0;
            width:210px !important;
            height:30px !important;
            vertical-align:middle;
            height:30px;
            display:inline-block !important;
        }
        #select{
            border: solid 1px #d0d0d0;
            width:120px;
            line-height:30px;
            height:30px;
            margin-right:10px;
        }
        #select option{
            width:100%;
            text-align:center;
        }
        h1{
            font-family: MicrosoftYaHei;
            font-size: 20px;
            font-weight: normal;
            color: #2a3137;
            margin-bottom: 26px;
            float: left;
        }
        .defualt{
            border:1px solid red;
        }
    </style>
</head>
<body
    <div class="header">
        <h1>血糖信息</h1>
    </div>
    <div class="test">
        <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
        <span class="title">新增血糖检测</span>
        <div>
            <div class="text_content" style="display:inline-block;width:370px;">
                <div>
                    <select name="select" id="select">
                        <option value="1">
                            空腹血糖:
                        </option>
                        <option value="2">
                            餐后两小时血糖:
                        </option>
                    </select>
                    <input type="text" class="form-control" id="fbgList" onkeyup="num(this)" style="margin-top:1px;" placeholder="请输入数值">
                    <span id="height_unit">mmol/L</span>
                </div>
            </div>
            <div style="display:inline-block;">
                <span class="time">检验时间：</span>
                <div style="display:inline-block;width:210px;vertical-align:middle">
                    <div class="times">
                        <div id="PrevTime" class="input-group date form_date" style="width: 100%"  data-date-format="yyyy-mm-dd">
                            <input id="beginDate" type="text" class="lay-date" readonly="readonly">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="change">
        <div class="form-group submitBtn" style="text-align: center ">
            <button type="button" class="btn" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">
                关闭
            </button>
            <button type="submit" class="btn" id="keep"  onclick="keep()" style="margin-left:20px;">保存</button>
        </div>
    </div>
    <script>
        // 初始化
        var diseasesType = ''
        var url = ''
        var type = ""
        function initLayDate(id) {
            laydate({
                elem: id,
                istime: true,
                format: 'YYYY-MM-DD hh:mm:ss',
                choose: function (dates) { //选择好日期的回调
                    // initTablePatient();
                }
            })
        }
        $(function(){
            initLayDate('#beginDate');
            var inputs = $('input')
            for( var a = 0; a < inputs.length; a++ ){
                $(inputs[a]).bind('change',function(){
                    if( $(this).val() != '' ){
                        $(this).removeClass('defualt')
                    }
                })
            }
            // 初始化获取当前时间
            var date=new Date();
            var year=date.getFullYear(); //获取当前年份
            var mon=date.getMonth()+1; //获取当前月份
            if( parseInt(mon) < 10 ){
                mon = '0' + mon
            }
            var da=date.getDate(); //获取当前日
            if( parseInt(da) < 10 ){
                da = '0' + da
            }
            var h=date.getHours(); //获取小时
            if( parseInt(h) < 10 ){
                h = '0' + h
            }
            var m=date.getMinutes(); //获取分钟
            if( parseInt(m) < 10 ){
                m = '0' + m
            }
            var s=date.getSeconds(); //获取秒
            if( parseInt(s) < 10 ){
                s = '0' + s
            }
            var d=document.getElementById('beginDate');
            d.value = year + '-' + mon + '-' + da + ' ' + h + ':' + m + ":" + s
            // 获取url 的idcard
            var href = location.search.split('?')[1]
            url = href.split('&')[0].split('=')[1]
            diseasesType = href.split('&')[1].split('=')[1]
            type = href.split('&')[2].split('=')[1]
        })
        //关闭并刷新
        function num(obj){
            obj.value = obj.value.replace(/\.{2,}/g,".");
        }
        function closeFrame() {
            window.parent.simpleCloseModal();
        }
        function keep(){
            // 判断当前的选择
            // 获取数据
            var fbgValue = $("#fbgList").val();
            var testItemCode = ''
            if( $('#select option:selected').attr('value') === '1' ){
                testItemCode = '105001'
            }else if(  $('#select option:selected').attr('value') === '2'  ){
                testItemCode = '105002'
            }
            if( fbgValue === "" ){
                var inputs = $('input')
                var arr = []
                for( var a = 0; a < inputs.length; a++ ){
                    if( $(inputs[a]).val() === '' ){
                        $(inputs[a]).attr('placeholder','请输入数值')
                        $(inputs[a]).addClass('defualt')
                        arr.push($(inputs[a]))
                    }
                }
                arr[0].focus()
                $(arr[0]).removeClass('defualt')
            }else{
                $.ajax({
                    url:"${URL_PATIENT_ADDBGINFO}",
                    dataType:"json",
                    type:"post",
                    data:{
                        idCard:url,
                        testValue:fbgValue,
                        testItemCode:testItemCode,
                        testTime:$('#beginDate').val(),
                        testKindCode:'105'
                    },
                    success:function(data){
                        if( data.success ){
                            // 刷新当前页面
                            parent.showSrc('${URL_PATIENT_TOARCHIVES}?idCard=' + url +'&diseasesType='+ diseasesType+'&type='+type)
                            closeFrame()
                        }
                    }
                })
            }
        }
    </script>
</body>
</html>
